package com.songjia.springcloud.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.songjia.common.model.base.ResponseInfo;

@RestController
public class DeptController {

	// 使用RestTemplate调用部门微服务提供者： “SpringCloud-01-dept-consumer” 提供的接口
	@Autowired
	private RestTemplate restTemplate;

	@GetMapping("/dept/{id}")
	public ResponseInfo get(@PathVariable("id") Long id) {
		return this.restTemplate.getForObject("http://localhost:8010/dept/{id}", ResponseInfo.class, id);
	}

	@GetMapping("/depts")
	public ResponseInfo getAll() {
		return this.restTemplate.getForObject("http://localhost:8010/depts", ResponseInfo.class);
	}
}